home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / LZW.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  4.5 KB  |  251 lines

  1. **********************************************************
  2. **  XFD external decruncher for LZW (compress.library)  **
  3. **          written and © 2000 by Georg Hörmann         **
  4. **********************************************************
  5. **
  6. ** 1.00    - Initial release.
  7. **
  8. **********************************************************
  9. **
  10. ** NOTE: Supports files from "KOE-II-Vikings" (with extra
  11. **     header) and plain files created by compress.library.
  12. **
  13.  
  14.         OUTPUT    "LIBS:xfd/LZW"
  15.  
  16.         INCDIR    "dh0:Include_Asm"    ;change this as you need it
  17.         INCLUDE    "libraries/xfdmaster.i"
  18.  
  19. *******************************************************
  20.  
  21.         moveq    #-1,d0        ;security
  22.         rts
  23.         dc.l    XFDF_ID        ;id
  24.         dc.w    1        ;version
  25.         dc.w    0
  26.         dc.l    0,0        ;private
  27.         dc.l    S_LZW        ;first slave
  28.  
  29.         dc.b    "$VER: LZW 1.00 (11.01.2000)",0
  30.  
  31. N_LZW        dc.b    "LZW (compress.library)",0
  32.         even
  33.  
  34. *******************************************************
  35.  
  36. S_LZW        dc.l    0        ;no more slaves
  37.         dc.w    2        ;version
  38.         dc.w    39        ;master version
  39.         dc.l    N_LZW        ;name
  40.         dc.w    XFDPFF_DATA|XFDPFF_RECOGLEN|XFDPFF_USERTARGET
  41.         dc.w    0
  42.         dc.l    RB_LZW        ;recog buffer
  43.         dc.l    DB_LZW        ;decrunch buffer
  44.         dc.l    0        ;recog segment
  45.         dc.l    0        ;decrunch segment
  46.         dc.w    0,0
  47.         dc.l    $16+2
  48.  
  49. ;-------------------------------------------------
  50.  
  51. RB_LZW        move.l    10(a0),d1    ;files from "KOE-II-Vikings"
  52.         bsr.s    .CheckID
  53.         tst.w    d0
  54.         beq.s    .TestPlain
  55.         move.l    14(a0),xfdrr_MinTargetLen(a1)
  56.         move.l    14(a0),xfdrr_FinalTargetLen(a1)
  57.         moveq    #10,d1
  58.         add.l    (a0),d1
  59.         move.l    d1,xfdrr_MinSourceLen(a1)
  60.         rts
  61.  
  62. .TestPlain    move.l    (a0),d1        ;basic compress.library files
  63.         bsr.s    .CheckID
  64.         tst.w    d0
  65.         beq.s    .Exit
  66.         move.l    4(a0),xfdrr_MinTargetLen(a1)
  67.         move.l    4(a0),xfdrr_FinalTargetLen(a1)
  68.         ;no MinSourceLen possible here !!
  69. .Exit        rts
  70.  
  71. .CheckID    moveq    #0,d0
  72.         move.b    d1,d0
  73.         and.l    #$ffffff00,d1
  74.         cmp.l    #("LZW"<<8),d1
  75.         bne.s    .CID_Exit
  76.         cmp.b    #"A",d0
  77.         blt.s    .CID_Exit
  78.         cmp.b    #"G",d0
  79.         bgt.s    .CID_Exit
  80.         rts
  81. .CID_Exit    moveq    #0,d0
  82.         rts
  83.  
  84. ;-------------------------------------------------
  85.  
  86. DB_LZW        movem.l    d2-d7/a2-a6,-(a7)
  87.         move.l    a0,a5
  88.         move.l    xfdbi_SourceBuffer(a5),a4
  89.  
  90.         cmp.w    #"LZ",(a4)
  91.         beq.s    .Plain
  92.         add.w    #10,a4
  93. .Plain        move.b    3(a4),d1
  94.         sub.b    #$38,d1
  95.         moveq    #3,d6
  96.         lsl.l    d1,d6
  97.         add.l    8(a4),d6
  98.  
  99.         move.l    d6,d0
  100.         moveq    #1,d1
  101.         move.l    xfdm_ExecBase(a6),a6
  102.         jsr    -198(a6)
  103.         tst.l    d0
  104.         bne.s    .MemOk
  105.         move.w    #XFDERR_NOMEMORY,xfdbi_Error(a5)
  106.         moveq    #0,d0
  107.         bra.s    .Exit
  108.  
  109. .MemOk        move.l    d0,a2
  110.         move.l    a4,a0
  111.         move.l    xfdbi_UserTargetBuf(a5),a1
  112.  
  113.         movem.l    d6/a2/a5/a6,-(a7)
  114.         bsr.s    Decr_LZW
  115.         movem.l    (a7)+,d6/a2/a5/a6
  116.  
  117.         exg    d0,d6
  118.         move.l    a2,a1
  119.         jsr    -210(a6)
  120.         move.l    d6,d0
  121.         bne.s    .Exit
  122.         move.w    #XFDERR_CORRUPTEDDATA,xfdbi_Error(a5)
  123.  
  124. .Exit        movem.l    (a7)+,d2-d7/a2-a6
  125.         rts
  126.  
  127. ;=================================================
  128.  
  129. * -> a0: source data
  130. * -> a1: target buffer
  131. * -> a2: lzw buffer
  132.  
  133. Decr_LZW    subq.w    #4,a7        ;exchange buffer
  134.         move.l    4(a0),-(a7)    ;decrunched length
  135.  
  136.         add.l    8(a0),a2
  137.         move.l    a2,a5
  138.         move.b    3(a0),d1
  139.         sub.b    #$38,d1
  140.         moveq    #0,d0
  141.         bset    d1,d0
  142.         add.l    d0,a2
  143.         move.l    a2,a6
  144.         move.l    a5,a3
  145.         move.l    a6,a4
  146.         move.l    #$00010203,d0
  147.         move.l    #$04040404,d3
  148.         move.w    #$40,d7
  149.         moveq    #-1,d2
  150. .l05D0        move.l    d0,(a3)+
  151.         add.l    d3,d0
  152.         move.l    d2,(a4)+
  153.         move.l    d2,(a4)+
  154.         dbra    d7,.l05D0
  155.  
  156.         moveq    #$20,d0
  157.         swap    d0
  158.         bset    d1,d0
  159.         swap    d0
  160.         add.w    #12,a0
  161.         move.l    (a0)+,d1
  162.         move.l    a5,a4
  163.         moveq    #0,d7
  164. .l05F2        moveq    #9,d3
  165.         move.l    d3,a2
  166.         moveq    #0,d2
  167.         bset    d3,d2
  168.         subq.l    #1,d2
  169.         move.l    #$103,d3
  170.         bsr.s    .l065E
  171.         move.l    d5,d4
  172.         move.l    d5,d6
  173.         subq.l    #1,(a7)        ;security check
  174.         bmi    .Error        ;
  175.         move.b    d5,(a1)+
  176. .l060C        sub.w    a2,d0
  177.         bpl.s    .l0618
  178.         swap    d1
  179.         move.w    (a0)+,d1
  180.         addq.w    #8,d0
  181.         addq.w    #8,d0
  182. .l0618        move.l    d1,d5
  183.         lsr.l    d0,d5
  184.         and.l    d2,d5
  185.         move.l    d5,a3
  186.         cmp.l    d3,d5
  187.         blt.s    .l0628
  188.         move.b    d6,-(a4)
  189.         move.l    d4,d5
  190. .l0628        move.b    (a5,d5.l),-(a4)
  191.         add.l    d5,d5
  192.         move.w    (a6,d5.l),d7
  193.         exg    d5,d7
  194.         bpl.s    .l0628
  195.         sub.w    #$200,d7
  196.         bcc.s    .l067A
  197.         move.b    (a4),d6
  198.  
  199.         add.l    (a7),a4        ;
  200.         sub.l    a5,a4        ;
  201.         bcs.s    .Error        ;
  202.         move.l    a4,4(a7)    ;security check
  203.         add.l    a5,a4        ;
  204.         sub.l    (a7),a4        ;
  205.         move.l    4(a7),(a7)    ;
  206.  
  207. .l063E        move.b    (a4)+,(a1)+
  208.         cmp.l    a4,a5
  209.         bne.s    .l063E
  210.         swap    d0
  211.         cmp.w    d3,d0
  212.         beq.s    .l0658
  213.         addq.l    #1,d3
  214.         move.b    d6,-1(a5,d3.l)
  215.         add.l    d3,d3
  216.         move.w    d4,-2(a6,d3.l)
  217.         lsr.l    #1,d3
  218. .l0658        swap    d0
  219.         move.l    a3,d4
  220.         bra.s    .l060C
  221.  
  222. .l065E        sub.w    a2,d0
  223.         bpl.s    .l066A
  224.         swap    d1
  225.         move.w    (a0)+,d1
  226.         addq.w    #8,d0
  227.         addq.w    #8,d0
  228. .l066A        move.l    d1,d5
  229.         lsr.l    d0,d5
  230.         and.l    d2,d5
  231.         rts
  232.  
  233. .l0672        addq.w    #1,a2
  234.         lsl.l    #1,d2
  235.         addq.l    #1,d2
  236.         bra.s    .l060C
  237.  
  238. .l067A        move.l    a5,a4
  239.         subq.l    #2,d7
  240.         bhi.s    .l0672
  241.         beq    .l05F2
  242.  
  243.         moveq    #1,d0
  244.         tst.l    (a7)
  245.         beq.s    .l0692
  246. .Error        moveq    #0,d0
  247. .l0692        addq.w    #8,a7
  248.         rts
  249.  
  250.         END
  251.